#!/bin/bash

VERSION=0.90
DESTINATION=${DESTINATION:-/opt/stoker}
SYSCONFDIR=${SYSCONFDIR:-/etc}
PROFILEDIR=${PROFILEDIR:-$SYSCONFDIR/profile.d}
DOCDIR=${DOCDIR:-/opt/stoker/doc/stoker-$VERSION}
MANDIR=${MANDIR:-/usr/share/man}

# Directories
mkdir -p "$DESTDIR$DESTINATION" "$DESTDIR$SYSCONFDIR" "$DESTDIR$PROFILEDIR"
mkdir -p "$DESTDIR$DOCDIR" "$DESTDIR$MANDIR"

# Core
install -Dpm 0644 *.py "$DESTDIR$DESTINATION"
install -Dpm 0755 stoker "$DESTDIR$DESTINATION/stoker"
cp -r scf2 translations "$DESTDIR$DESTINATION"

# Config
install -Dpm 0600 stoker.conf.example "$DESTDIR$SYSCONFDIR/stoker.conf.example"
install -Dpm 0600 stoker.machines.example \
     "$DESTDIR$SYSCONFDIR/stoker.machines.example"

# Docs
install -Dpm 0644 CHANGELOG LICENSE NOTICE TIPS-AND-TRICKS TODO TRANSLATING \
     "$DESTDIR$DOCDIR"

# Man pages
for n in `ls man/`; do
	extn=`echo $n | awk -F . '{print $NF}'`
   install -Dpm 0644 man/$n "$DESTDIR$MANDIR/man$extn/$n"
done

# profile.d
cat profile.d/stoker.sh.in | sed s,%DEST%,$DESTINATION, > profile.d/stoker.sh
cat profile.d/stoker.csh.in | sed s,%DEST%,$DESTINATION, > profile.d/stoker.csh
install -Dpm 0755 profile.d/stoker.sh "$DESTDIR$PROFILEDIR/stoker.sh"
install -Dpm 0755 profile.d/stoker.csh "$DESTDIR$PROFILEDIR/stoker.csh"
